import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
import math


def rate():
    """复利"""
    data = pd.DataFrame()

    data["frequency"] = np.arange(1, 15, 1)
    data["final_value"] = 100*((1+0.1/data['frequency'])**data['frequency'])
    data.plot(figsize=(10, 6), x='frequency', y='final_value', style='o-')
    plt.show()


def func(y):
    e = math.e
    return 3*e**(-y*0.5)+3*e**(-y*1)+3*e**(-y*1.5)+103*e**(-y*2)-98.39


def zq_rate():
    y = fsolve(func, 0.1)
    print(y)


def data_rate():
    data = pd.DataFrame()
    data['maturity'] = [0.25, .5, 1, 1.5, 2]
    data['coupon'] = [0, 0, 0, 8, 12]
    data['principal'] = [100] * 5
    data['price'] = [97.5, 94.9, 90, 96, 101.6]
    data['zero_rate'] = [np.nan] * 5
    print(data)


if __name__ == '__main__':
    # rate()
    # zq_rate()
    data_rate()

